<style scoped>
    .layui-form >>> .layui-form-select{
        z-index: inherit;
    }
</style>

<template>
    <div class="company">
        <fieldset class="layui-elem-field layui-field-title">
            <legend>添加田检项</legend>
        </fieldset>

        <form class="layui-form " >
            <div class="layui-form-item">
                <label class="layui-form-label">田检项名称</label>
                <div class="layui-input-block">
                    <input type="text" name="name" :value="pci.name" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">田检标准</label>
                <div class="layui-input-block">
                    <select id="pcguid" name="plckid" lay-filter="pcguid" lay-verify="required" lay-search="">
                        <option value="">请选择</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">编号</label>
                <div class="layui-input-block">
                    <input type="text" name="code" :value="pci.code" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">必填</label>
                <div class="layui-input-block">
                    <select id="required" name="required" lay-filter="required" lay-verify="required">
                        <option value="1">是</option>
                        <option value="2">否</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="submit">立即提交</button>
                    <button class="layui-btn layui-btn-primary" @click="$parent.back">返回</button>
                </div>
            </div>
            <div style="height: 500px"></div>
        </form>
    </div>
</template>

<script>
    export default {
        name: 'AddPlantCheckitems',
        props: ['id'],
        data () {
            return {
                guid : this.id,
                pci: {}
            }
        },
        mounted() {
            let that = this;
            layui.use(['form'], function () {
                var form = layui.form,
                    layer = layui.layer;
                let loader = layer.load();
                $.ajax({
                    url: '/farmer/Plantcheck!viewAll.action',
                    data: {},
                    type: "post",
                    dataType: "json",
                    success: function(res) {
                        if (res.info != "error") {
                            $.each(res.result, function (index, item) {

                                    $('#pcguid').append("<option   value="  +item.guid +  " >" + item.name    + "</option>" );

                            });

                            form.render('select');
                        } else {
                            that.toast("系统错误");
                        }
                    },
                    complete: function () {
                        layer.close(loader);
                    }
                });

                //提交编辑过的数据
                form.on('submit(submit)', function (data) {
                    let loader = layer.load();
                    $.ajax({
                        url: '/farmer/Plantcheckitems!save.action',
                        data: data.field,
                        type: "post",
                        dataType: "json",
                        success: function(res) {
                            if (res.info == "success") {
                                that.toast("添加成功");
                                that.$parent.switchPage('PlantCheckitems');
                            }else if(res.info == "isCodeHave"){
                                that.toast("编码已存在");
                            } else if(res.info == "isPlantNameHave"){
                                that.toast("田检项名称已存在");
                            }else{
                                that.toast("系统错误");
                            }
                        },
                        complete: function () {
                            layer.close(loader);
                        }
                    });
                    return false;
                });
            });
            this.getStandards();
        },
        updated() {
            layui.form.render();
        },
        methods: {
            back: function () {
                this.$parent.switchPage(this.$parent.refView);
            },
            getqamain: function (){

            }

        }
    }
</script>
